package com.spring.appservice.web.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.spera.genutil.MemberCardZxing;
import com.spera.genutil.TokenUtil;
import com.spring.api.web.service.EnvizApiService;
import com.spring.appservice.web.dao.MainShowMapper;
import com.spring.appservice.web.mainShowModel.CourseOpenDetail;
import com.spring.appservice.web.mainShowModel.CourseTypeProduct;
import com.spring.appservice.web.mainShowModel.Journal;
import com.spring.appservice.web.mainShowModel.Packages;
import com.spring.appservice.web.mainShowModel.UserPackage;
import com.spring.appservice.web.model.Activity;
import com.spring.appservice.web.model.News;
import com.spring.appservice.web.requestModel.BaseFile;
import com.spring.appservice.web.requestModel.JournalUser;
import com.spring.appservice.web.service.MainShowService;
import com.spring.comment.web.service.CommentService;
import com.spring.common.web.service.CommonService;
import com.spring.daily.web.dto.DailyParamter;
import com.spring.daily.web.service.DailyService;
import com.spring.myspace.web.dao.MySpaceMapper;
import com.spring.myspace.web.service.MySpaceService;
import com.spring.security.core.util.ApplicationUtils;
import com.spring.security.web.dao.JedisCache;
import com.spring.security.web.model.BaseResult;
import com.spring.sperapc.web.dao.AppProjectVersionMapper;
import com.spring.sperapc.web.model.AppProjectVersion;
import com.spring.tools.MyTools;
import com.sso.api.web.dao.SsoMapper;
import com.sso.api.web.dao.TracelogboMapper;
import com.sso.api.web.model.TracelogboWithBLOBs;

@Service
public class MainShowServiceImpl implements MainShowService{
	
	@Resource private JedisCache jedisCache;
	
	@Resource 
	private SsoMapper ssoMapper;	
	
	@Resource 
	private MyTools myTools;	
	
	@Resource 
	private MainShowMapper mainShowMapper;
	
	@Resource 
	private CommentService commentService;	
	
	@Resource 
	private EnvizApiService envizApiService;	

	@Resource 
	private AppProjectVersionMapper appProjectVersionMapper;
	
	@Resource 
	private MySpaceMapper mySpaceMapper;

	@Resource 
	private CommonService commonService;

	@Resource 
	private MySpaceService mySpaceService;

	@Resource 
	private DailyService dailyService;	
	
	@Resource 
	private  TracelogboMapper tracelogboMapper;

	@Override
	public BaseResult getLastAppVersion(String packageName,String appID,String appType) {
		
		BaseResult br=null;
		HashMap<String,Object> hm=new HashMap<String,Object>();
		if(appType.equals("1")){
			if(packageName==null){
				return new BaseResult("0","请输入packageName"); 	
			}

		}else if(appType.equals("2")){
			if(packageName==null&&appID==null){
				return new BaseResult("0","请输入packageName或者appID"); 	
			}
			hm.put("appID", appID);
		}else{
			return new BaseResult("0","请输入有效apptype");
		}
		
		hm.put("packageName", packageName);
		hm.put("appType", appType);
		
		List<AppProjectVersion> apv=appProjectVersionMapper.selectByAppProjectID(hm);
		
		br=new BaseResult("1","查询成功",apv);
		
		return br;
		
	}	

	@Override
	public BaseResult banner(String bannerType,String skip,String rows){
		HashMap<String,Object> hm = MyTools.pageIndexToSkip(null, null, skip, rows);
		hm.put("bannerType", bannerType);
		
		List<Map<String,Object>> bannersList = mainShowMapper.getBannersList(hm);
		return new BaseResult("1","查询成功",bannersList);
	}
	
	
	@Override
	public Map<String,Object> homeShow(String kids_parkID,String token) throws Exception {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
	
		HashMap hmc=MyTools.checkIsNotNull(kids_parkID);
		if(hmc!=null){
			return hmc;
		}
		
		int courseRows=6;
		//int activitesList=1000;
		//int teacherRows=1000;
		int baners=10000;
		//int daily=2;
		
		
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("kids_parkID", kids_parkID);
		hm.put("skip", 0);
		
		hm.put("rows", baners);
		hm.put("bannerType", 2);
		List<Map<String,Object>> bannersList = mainShowMapper.getBannersList(hm);
		
		
		//courses页
		hm.put("rows", courseRows);
		List<Map<String,Object>> coursesList = mainShowMapper.getCoursesList(hm);
		

		

		//teachers页
/*		hm.put("rows", teacherRows);
		List<Map<String,Object>> teachersList = mainShowMapper.getTeachersList(hm);*/
		
		//activities页
/*		hm.put("rows", activitesList);
		List<Map<String,Object>> activitiesList = mainShowMapper.getActivitiesList(hm);*/
		
//		if (t == null) {
//			//return t;
//			String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
//			String c_family_id = jedisCache.hget(token, TokenUtil.FAMILY_ID);
//			
//			//课程提醒		
//			HashMap<String,Object> hm2=new HashMap<String,Object>();
//			hm2.put("c_user_id", c_user_id);	
//			String[] userList=ssoMapper.getBabyIDByFamilyID(hm2);
//			
//			HashMap<String,Object> hm3=new HashMap<String,Object>();
//			hm3.put("userList", userList);
//			List<Map<String,Object>> nearCoursesList =mainShowMapper.getNearCoursesList(hm3);
//			
//					
//			//摄像头
//			Map<String,Object> parm = Maps.newHashMap();
//			parm.put("kidsPark", kids_parkID);
//			parm.put("c_family_id", c_family_id);		
//			List<Map<String, Object>> ezvizList=envizApiService.ezvizs(parm);
//			
//			if(ezvizList==null||ezvizList.size()==0){
//				ezvizList=new ArrayList<Map<String, Object>>();
//			}else{
//				String accessToken=envizApiService.accessToken(parm);
//				dataset.put("accessToken", accessToken);				
//			}
//			
//			//最新空间动态
//			List<Map<String, Object>> NearMSJournal=mainShowMapper.getNearMSJournalList(c_family_id);
//			
//			dataset.put("nearCoursesList", nearCoursesList);
//			dataset.put("ezvizList", ezvizList);
//			dataset.put("nearMSJournal", NearMSJournal);
//		}
		
		//hm.put("productShowTypeCode", 3);
		hm.put("rows", 8);
		
		List<Map<String,Object>> living=mainShowMapper.getProductShow(hm);
		
		dataset.put("banners", bannersList);
		dataset.put("courses", coursesList);
//		dataset.put("activities", activitiesList);

		dataset.put("living", living);
		
		retM.put(ApplicationUtils.DATASET, dataset);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}
	
	@Override
	public Map<String,Object> homeMemberShow(String kids_parkID,String token) throws Exception {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		
		if (t == null) {
			//return t;
			String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
			String c_family_id = jedisCache.hget(token, TokenUtil.FAMILY_ID);
			
			//课程提醒		
			HashMap<String,Object> hm2=new HashMap<String,Object>();
			hm2.put("c_user_id", c_user_id);	
			String[] userList=ssoMapper.getBabyIDByFamilyID(hm2);
	
			List<Map<String,Object>> nearCoursesList = new ArrayList<Map<String,Object>>();
			if(userList.length>0){
				HashMap<String,Object> hm3=new HashMap<String,Object>();
				hm3.put("userList", userList);
				nearCoursesList=mainShowMapper.getNearCoursesList(hm3);
			}		
	
			//摄像头
			Map<String,Object> parm = Maps.newHashMap();
			parm.put("kidsPark", kids_parkID);
			parm.put("c_family_id", c_family_id);		
			List<Map<String, Object>> ezvizList=envizApiService.ezvizs(parm);
			
			if(ezvizList==null||ezvizList.size()==0){
				ezvizList=new ArrayList<Map<String, Object>>();
			}else{
				String accessToken=envizApiService.accessToken(parm);
				dataset.put("accessToken", accessToken);				
			}
			
			//最新空间动态
			List<Map<String, Object>> NearMSJournal=mainShowMapper.getNearMSJournalList(c_family_id);
			
			//日记			
			DailyParamter dailyParamter=new DailyParamter();
			dailyParamter.setRows(2);
			dailyParamter.setToken(token);
			dailyParamter.setHasRepied(0);
			dailyParamter.setHasread(0);
			dataset.put("daily", dailyService.daily(dailyParamter).getDataset());

			dataset.put("nearCoursesList", nearCoursesList);
			dataset.put("ezvizList", ezvizList);
			dataset.put("nearMSJournal", NearMSJournal);
		}
		
		retM.put(ApplicationUtils.DATASET, dataset);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		return retM;
	}
	
	
	
	@Override
	public BaseResult getActivitiesList(String kidsParkID,String skip,String rows){
		BaseResult b=null;
		
		HashMap<String,Object> hm=MyTools.pageIndexToSkip(null, null, skip, rows);
		hm.put("kids_parkID", kidsParkID);

		List<Activity> activity=mainShowMapper.getActivitiesList(hm);		
		
		b=new BaseResult("1","查询成功",activity);
		
		return b;
	}
	
	@Override
	public BaseResult getNewsList(String newsID,String newsType,String skip,String rows,HttpServletRequest request) throws Exception{
		BaseResult b=null;
		
		HashMap<String,Object> hm=MyTools.pageIndexToSkip(null, null, skip, rows);
		hm.put("newsType", newsType);
		hm.put("newsID", newsID);

		List<News> activity=mainShowMapper.getNewsList(hm);	
		
		if(newsID!=null){
			commonService.checkIsNewAddr(newsID, "1", request);
		}
	
		b=new BaseResult("1","查询成功",activity);
		
		return b;
		
		
	}
	
	@Override
	public Map<String,Object> getProductShowDetail(String productShowID) {
		Map<String,Object> retM=new HashMap<String,Object>();
		//Map<String,Object> dataset=new HashMap<String,Object>();
		
		HashMap hmc=MyTools.checkIsNotNull(productShowID);
		if(hmc!=null){
			return hmc;
		}
		
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("productShowID", productShowID);	

		
		List<Map<String,Object>> dataset=mainShowMapper.getProductShowDetail(hm);		
		
		retM.put(ApplicationUtils.DATASET, dataset);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
		
	}
	
	@Override
	public Map<String,Object> productShow(String kids_parkID) {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		
		HashMap hmc=MyTools.checkIsNotNull(kids_parkID);
		if(hmc!=null){
			return hmc;
		}
		
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("kids_parkID", kids_parkID);	
		hm.put("productShowTypeCode", 1);
		hm.put("skip", 0);
		hm.put("rows", 2);
		
		List<Map<String,Object>> education=mainShowMapper.getProductShow(hm);
		
		hm.put("productShowTypeCode", 2);
		
		List<Map<String,Object>> healthy=mainShowMapper.getProductShow(hm);
		
		hm.put("productShowTypeCode", 3);
		hm.put("rows", 10000);
		
		List<Map<String,Object>> living=mainShowMapper.getProductShow(hm);
		
		
		//得到早教课程系列
		HashMap<String,Object> hm2=new HashMap<String,Object>();
		hm2.put("kids_parkID", kids_parkID);	
		hm2.put("course_typeID", "0a03bcb3-bbc0-44e4-b4ae-aff02aa83718");
		hm2.put("skip", 0);
		hm2.put("rows", 6);
		CourseTypeProduct zaojiao=mainShowMapper.getCourseProduct(hm2);
		
		
		//得到成长系列
		hm2.put("course_typeID", "05dd7241-23a7-4b5a-8696-3ce32ed3448d");
		hm2.put("rows", 3);		
		CourseTypeProduct chengzhagn=mainShowMapper.getCourseProduct(hm2);
		
		List<CourseTypeProduct> courseCategories=new ArrayList<CourseTypeProduct>();
		
		courseCategories.add(zaojiao);
		courseCategories.add(chengzhagn);
		
		
		dataset.put("courseCategories", courseCategories);		
		dataset.put("education", education);
		dataset.put("healthy", healthy);
		dataset.put("living", living);	
		
		retM.put(ApplicationUtils.DATASET, dataset);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}
	

	
	@Override
	public Map<String,Object> meShow(String token) {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();

		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);

		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("c_user_id", c_user_id);
		//查询课程数量
		Map<String,Object> courseQuantity=mainShowMapper.getCourseQuantity(hm);

		//查询最近的课程
		String[] userList=ssoMapper.getBabyIDByFamilyID(hm);		

		Map<String,Object> nearestCourseAppoint = null;
		if(userList!=null&&userList.length>0){
			HashMap<String,Object> hm2=new HashMap<String,Object>();
			hm2.put("userList", userList);
			nearestCourseAppoint= mainShowMapper.getNearestCourseAppoint(hm2);
		}
		
		Map<String,Object> f=new HashMap<String,Object>();
		
		if(courseQuantity!=null){
			f.putAll(courseQuantity);
		}
		
		//course
		if(nearestCourseAppoint!=null){
			f.putAll(nearestCourseAppoint);
		}		
		
		BigDecimal dreamFund=ssoMapper.getUserPoint(hm);
		if(dreamFund==null){
			dreamFund = new BigDecimal("0");
		}
		
		List<Map<String, Object>> packages=mainShowMapper.getPackageList(hm);
		List<Map<String, Object>> rechargeCards=mainShowMapper.getRechargeList(hm);
		
		dataset.put("dreamFund", dreamFund);
		dataset.put("course", f);
		dataset.put("packages", packages);
		dataset.put("rechargeCards", rechargeCards);
	
		retM.put(ApplicationUtils.DATASET, dataset);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}

	
	@Override
	public BaseResult zoneInfo(String token,String zoneType) {
		BaseResult retM=new BaseResult();

		BaseResult t = TokenUtil.checkTokenBR(token, jedisCache);
		if (t != null) {
			return t;
		}
		String c_family_id = jedisCache.hget(token, TokenUtil.FAMILY_ID);

		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("c_family_id", c_family_id);
		hm.put("spaceType", zoneType);
		
		List<Map<String, Object>>  list=mainShowMapper.getMySpace(hm);
		if(list.size()!=0){
			retM.setDataset(list.get(0));
		}else{
			retM.setDataset(new HashMap<String, Object>());
		}
		retM.setMsg("查询成功");
		return retM;
	}

	
	@Override
	public Map<String,Object> updateZoneInfo(String babyID,String zoneType, String title, MultipartFile avatar, MultipartFile cover,String token)
			throws Exception {
		Map<String,Object> retM=new HashMap<String,Object>();
		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
	
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("c_user_id", babyID);

		if(cover!=null){
		if(!cover.isEmpty()){
		Map<String, Object> hmr2=myTools.commitFile2("myspace", cover);
		if(hmr2.get(ApplicationUtils.STATUS).equals("1")){
			String coverID= MyTools.ObjectToString(hmr2.get("fileID"));
			hm.put("coverID", coverID);
		}else{
			retM.put(ApplicationUtils.STATUS, "0");
			retM.put(ApplicationUtils.MSG, "上传封面失败");		
			return retM;
		}
		}
		}
		int effect=0;
		
		int count=mainShowMapper.getMySpaceCount(hm);
		
		if(count==0){
			 effect=mainShowMapper.insertMySpace(hm);
		}else{
			 effect=mainShowMapper.udpateMySpace(hm);
		}
		
		
		if(effect==0){
			retM.put(ApplicationUtils.STATUS, "0");
			retM.put(ApplicationUtils.MSG, "修改失败");		
			return retM;
		}
	
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "修改成功");
		
		return retM;
	}

	
	
	
	@Override
	public Map<String,Object> timeline(String babyID,String pageSize,String pageIndex,String skip,String rows,String token,String isTeacher) {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();

		String c_user_id=null;
		String c_family_id=null;
		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t == null) {
			c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
			c_family_id = jedisCache.hget(token, TokenUtil.FAMILY_ID);
		}else{
			//return t;
		}
		
		HashMap<String,Object> hm=MyTools.pageIndexToSkip(pageSize, pageIndex, skip, rows);
		hm.put("c_user_id", c_user_id);
		hm.put("c_family_id", c_family_id);
		
		String[] userList=ssoMapper.getBabyIDByFamilyID(hm);
		if(userList.length==0){
			userList=null;
		}
		
		hm.put("userList", userList);
		
		hm.put("babyID", babyID);
		hm.put("isTeacher", isTeacher);
		
		int count=0;
		count=mainShowMapper.getJournalCount(hm);
		
		//不再生成系统日志
/*		if(babyID!=null){
		if(count==0){
			HashMap<String,Object> hm2=new HashMap<String,Object>();
			hm2.put("title", "系统消息");
			hm2.put("content", "用蒂芭卜记录宝宝空间的每一个笑容，每一次哭泣。宝宝成长的每一步，蒂芭卜与您一起守护。");
			hm2.put("c_user_id", babyID);
			hm2.put("c_family_id", c_family_id);
			hm2.put("c_user_name", "蒂芭卜");
			hm2.put("publishUserTypeCode", "3");
			hm2.put("osType", "3");
			
			//int effect= mainShowMapper.insertJournal(hm2);
			count=1;
			
			}
		}*/
		//查询日志
		List<com.spring.appservice.web.mainShowModel.Journal> journal=Lists.newArrayList();
		//if(userList.length>0){
			journal=mainShowMapper.getJournalList(hm);
		//}
		//查询用户头像
	//	String[] journal=String[] 
		List<String> parentUserList=new ArrayList<String>();
		
		for(Journal jnl:journal){
			String publishUserId=jnl.getPublishUserId();
			if(jnl.getPublishUserTypeCode().equals("1")){
				parentUserList.add(publishUserId);
			}	
		}		
		if(parentUserList.size()>0){
			HashMap<String,Object> hm3=new HashMap<String,Object>();
			hm3.put("userList", parentUserList);
			
			List<com.spring.appservice.web.mainShowModel.Journal> photoList= ssoMapper.getUserImage(hm3);
			
			for(Journal jnl:journal){
				for(Journal pl:photoList){
					if(jnl.getPublishUserId()!=null){
						if(jnl.getPublishUserId().equals(pl.getPublishUserId())){
							jnl.setPublishUserImage(pl.getPublishUserImage());
						}
					}
					
				}
			}
		}

		retM.put(ApplicationUtils.DATASET, journal);
		retM.put("total",count);
		retM.put("count",journal.size());
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}
	
	@Override
	public Map<String,Object> courseList(String categoryId,String kids_parkID,String pageSize,String pageIndex,String skip,
			String rows,String token) {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		
		HashMap hmc=MyTools.checkIsNotNull(kids_parkID);
		if(hmc!=null){
			return hmc;
		}
		
		HashMap<String,Object> hm=MyTools.pageIndexToSkipSearchAllLimit(pageSize, pageIndex, skip, rows);
		hm.put("course_typeID", categoryId);
		hm.put("kids_parkID", kids_parkID);
		
		List<Map<String,Object>> courseList=mainShowMapper.getCoursesList(hm);

		retM.put(ApplicationUtils.DATASET, courseList);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}
	
	@Override
	public Map<String,Object> teacherList(String kids_parkID,String pageSize,String pageIndex,String skip,
			String rows,String token) {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		
		HashMap hmc=MyTools.checkIsNotNull(kids_parkID);
		if(hmc!=null){
			return hmc;
		}
		
		HashMap<String,Object> hm=MyTools.pageIndexToSkipSearchAllLimit(pageSize, pageIndex, skip, rows);
		hm.put("kids_parkID", kids_parkID);
		
		List<Map<String,Object>> teacherList=mainShowMapper.getTeachersList(hm);
		

		retM.put(ApplicationUtils.DATASET, teacherList);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}
	
	
	@Override
	public Map<String,Object> freePackage(String kids_parkID,String pageSize,String pageIndex,String skip,
			String rows) {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		
		HashMap hmc=MyTools.checkIsNotNull(kids_parkID);
		if(hmc!=null){
			return hmc;
		}
		
		HashMap<String,Object> hm=MyTools.pageIndexToSkipSearchAllLimit(pageSize, pageIndex, skip, rows);
		hm.put("kids_parkID", kids_parkID);
		
		List<Packages> packages=mainShowMapper.freePackage(hm);
		if(packages.size()!=0){
			retM.put(ApplicationUtils.DATASET, packages.get(0));
		}

		//retM.put(ApplicationUtils.DATASET, packages);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}
	

	
	@Override
	public Map<String,Object> bookProduct(String productId, String productType, String name, 
			String babyAge, String mobile, String captcha) throws Exception{
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		
		HashMap hmc=MyTools.checkIsNotNull(productId,productType,mobile);
		if(hmc!=null){
			return hmc;
		}
	
		HashMap hmc2= myTools.checkCaptcha(mobile, captcha);
		if(hmc2!=null){
			return hmc2;
		}
		
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("productId", productId);
		hm.put("productTypeCode", productType);
		hm.put("name", name);
		hm.put("babyAge", babyAge);
		hm.put("phone", mobile);

		int count=mainShowMapper.checkAppointment(hm);
		if(count>0){
			retM.put(ApplicationUtils.STATUS, "0");
			retM.put(ApplicationUtils.MSG, "请勿重复预约");
			return retM;
			
		}
		
		int effect=mainShowMapper.insertAppointment(hm);
		
		if(effect<1){
			retM.put(ApplicationUtils.STATUS, "0");
			retM.put(ApplicationUtils.MSG, "预约失败");
			return retM;			
		}

		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "预约成功，稍后我们的工作人员将于您联系！如有任何疑问请致电86-021-62037631，我们将竭诚为您服务!");
		
		return retM;
	}
	
	@Override
	public Map<String,Object> lessonList(String attendType, String startTime,
			String endTime, String skip, String rows, String pageSize, String pageIndex,String token) {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
		
		
		HashMap hmc=MyTools.checkIsNotNull(attendType);
		if(hmc!=null){
			return hmc;
		}
		if(attendType.equals("1")){
			attendType="0";
		}else if(attendType.equals("2")){
			attendType="1";
		}else{
			attendType=null;
		}
				
		HashMap<String,Object> hm=MyTools.pageIndexToSkip(pageSize, pageIndex, skip, rows);
		hm.put("attendType", attendType);
		hm.put("startTime", startTime);
		hm.put("endTime", endTime);
		hm.put("c_user_id", c_user_id);
		
		
		String[] userList= ssoMapper.getBabyIDByFamilyID(hm);
		if(userList.length<1){
			retM.put(ApplicationUtils.STATUS, "0");
			retM.put(ApplicationUtils.MSG, "该用户没有小孩");			
			return retM;
		}
		
		hm.put("userList", userList);		
		
		List<Map<String, Object>> courseList=mainShowMapper.myCourseList(hm);
		int total=mainShowMapper.myCourseListCount(hm);
		
		retM.put(ApplicationUtils.DATASET, courseList);
		retM.put("count", courseList.size());
		retM.put("total", total);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}
	
	@Override
	public Map<String,Object> lessonDetail(String token,String appointmentID) {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		
		HashMap hmc=MyTools.checkIsNotNull(appointmentID);
		if(hmc!=null){
			return hmc;
		}
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
		
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("appointmentID", appointmentID);
		hm.put("c_user_id", c_user_id);		
		
		
		CourseOpenDetail courseDetail=mainShowMapper.getCourseDetail(hm);
		List<Map<String, Object>> file=mainShowMapper.getCourseDetailFile(hm);
		List<Map<String, Object>> teacherComment=mainShowMapper.getCourseTeacherComment(hm);
		int status=mainShowMapper.getCourseStatus(hm);
		
		if(file!=null){
			courseDetail.setFiles(file);
		}
		if(teacherComment!=null){
			courseDetail.setTeacherComments(teacherComment);
		}

		courseDetail.setStatus(status);
		
		ArrayList al=new ArrayList();
		al.add(courseDetail);
		
		retM.put(ApplicationUtils.DATASET, al);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}
	

	@Override
	public Map<String,Object> userPackage(String userPackageId) {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		
		HashMap hmc=MyTools.checkIsNotNull(userPackageId);
		if(hmc!=null){
			return hmc;
		}

		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("contract_packageID", userPackageId);
	
		UserPackage up=mainShowMapper.getPackageDetail(hm);

		retM.put(ApplicationUtils.DATASET, up);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}
	
	
	@Override
	public Map<String,Object> consumingRecord(String token,String id, String idType, String skip, String rows,
			String pageSize, String pageIndex) {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
		

		
		HashMap<String,Object> hm=MyTools.pageIndexToSkipSearchAllLimit(pageSize, pageIndex, skip, rows);
		hm.put("c_user_id", c_user_id);
		hm.put("idType", idType);
	
		List<Map<String, Object>> list=mainShowMapper.getOrderDetail(hm);

		retM.put(ApplicationUtils.DATASET, list);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}
	
	
	@Override
	public Map<String,Object> getCourseComment(String lessonId, String skip, String rows, String pageSize, String pageIndex) {
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		
//		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
//		if (t != null) {
//			return t;
//		}
//		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
		
		
		HashMap<String,Object> hm=MyTools.pageIndexToSkipSearchAllLimit(pageSize, pageIndex, skip, rows);
		hm.put("appointmentID", lessonId);
	
		List<Map<String, Object>> list=mainShowMapper.getCourseComment(hm);

		retM.put(ApplicationUtils.DATASET, list);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");
		
		return retM;
	}
	

	
	@Override
	public Map<String,Object> commentLesson(String token,String lessonId, String content, String score) throws Exception{
		Map<String,Object> retM=new HashMap<String,Object>();
		Map<String,Object> dataset=new HashMap<String,Object>();
		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
		
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("appointmentID", lessonId);
		
		String detailID=mainShowMapper.getDetailIDByAppointment(hm);
		
		Map<String,Object> r=commentService.createCommentCustomerService(token, detailID, null, null, null, "1002", "2", content);
		if(r.get(ApplicationUtils.STATUS).equals("0")){
			return r;
		}
		String commentID=String.valueOf(r.get(ApplicationUtils.DATASET));

		hm.put("commentID", commentID);
		hm.put("score", score);
	
		int effect=mainShowMapper.insertCommentScore(hm);

		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "评论成功");
		
		return retM;
	}
	
	
	@Override
	public Map<String,Object> feedback(String userID,String feedbackTypeCode,String content, String mobile, String name) throws Exception{
		Map<String,Object> retM=new HashMap<String,Object>();
		
/*		Map<String,Object> c=MyTools.checkIsNotNull(userID,feedbackTypeCode,content,name);
		if(c != null){
			return c;
		}*/
		
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("userID", userID);
		hm.put("feedbackTypeCode", feedbackTypeCode);
		hm.put("content", content);
		hm.put("phone", mobile);
		hm.put("userName", name);
		
		int effect=mainShowMapper.feedback(hm);
		if(effect<1){
			retM.put(ApplicationUtils.STATUS, "0");
			retM.put(ApplicationUtils.MSG, "反馈失败");
			return retM;
		}

		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "信息提交成功，感谢您的反馈！");		
		return retM;
	}
	
	
	
	@Override
	public Map<String,Object> getMemberCardStatus(String token) throws Exception{
		Map<String,Object> retM=new HashMap<String,Object>();	
		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);

		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("c_user_id", c_user_id);
		
		Map<String,Object> mcs=ssoMapper.getMemberCardStatus(c_user_id);
		
		String card_number=MyTools.ObjectToString(mcs.get("card_number"));
		String card_out_number=MyTools.ObjectToString(mcs.get("card_number"));		
				/*		String uuid=null;
		if(card_number!=null){
			uuid = MemberCardZxing.SetSperaToken(jedisCache, card_number);		
			String real_card_number=jedisCache.get(uuid);
			System.out.println("real_card_number"+real_card_number);
		}
		*/
		
		String member_isvaild=MyTools.ObjectToString(mcs.get("member_isvaild"));
		
		HashMap<String,Object> hmr=new HashMap<String,Object>();
		
		int state=0;
		
		if(card_number==null){
			state=0;
		}else{
			HashMap<String, Object> rechargeDetail=mainShowMapper.getRechargeDetail(card_number);
			List<UserPackage> packageDetail=mainShowMapper.getCardDetail(card_number);
			hmr.putAll(rechargeDetail);
			hmr.put("packageDetail", packageDetail);
		}
		if(card_number!=null&&member_isvaild.equals("1")){
			state=1;
		}
		if(card_number!=null&&member_isvaild.equals("0")){
			state=2;
		}

		hmr.put("state", state);
		hmr.put("card_number", card_number);
		hmr.put("card_out_number", card_out_number);
		
		retM.put(ApplicationUtils.DATASET, hmr);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");	
		
		if(state==0){
			retM.put(ApplicationUtils.MSG, "您还不是会员请注册会员");	
		}
		
		return retM;
	}
	

	
	@Override
	public Map<String,Object> updateMemberIsValid(String memberCard,String token,HttpServletRequest request) throws Exception{
		Map<String,Object> retM=new HashMap<String,Object>();		
		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
		
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("card_number", memberCard);
		
		int effect2=ssoMapper.updateMemberIsValid(hm);
		if(effect2<1){
			retM.put(ApplicationUtils.STATUS, "0");
			retM.put(ApplicationUtils.MSG, "挂失失败或者已经挂失");		
			return retM;
		}
		
		int effect=ssoMapper.updateFamilyMemberIsValid(hm);
		
		if(effect<1){
			throw new Exception();
		}

		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "挂失成功");
		
		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
		
		TracelogboWithBLOBs tl = MyTools.getLog(jedisCache, token, request);
		tl.setEntitytypename("c_family_member");
		tl.setEntityid(c_user_id);
		tl.setLogcategory(2);
		tl.setLogdescription(MyTools.getChangeByMap(hm,"修改"));
		int effect3=tracelogboMapper.insert(tl);
		System.out.println(effect3);
		
		return retM;
	}
	public Boolean b=false;
	
	//创建邀请码
	@Override
	public Map<String, Object> createInviteCode(String token,String roleId) throws Exception{
		Map<String, Object> m = Maps.newHashMap();

		Map<String, Object> t = TokenUtil.checkToken(token,jedisCache);
		if (t != null) {
			return t;
		}

		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
		String c_family_id = jedisCache.hget(token, TokenUtil.FAMILY_ID);
		String c_role_id = jedisCache.hget(token, TokenUtil.ROLE_ID);
		//如果角色为空，则使用与当前角色相反的角色
		if(StringUtils.isBlank(roleId)){
			roleId = ("1".equals(c_role_id))?"2":"1";
		}
		
		//生成的邀请码
		int gcode=0;
		HashMap<String, Object> param = Maps.newHashMap();
		param.put("c_user_id", c_user_id);
		param.put("c_family_id", c_family_id);
		param.put("c_role_id", roleId);
		List<Map<String,Object>> unUsedCount = ssoMapper.getUnUsedInviteCode(param);
		if(unUsedCount!=null&&unUsedCount.size()>0){
			Map<String,Object> rm = unUsedCount.get(0);
			gcode = Integer.parseInt(ApplicationUtils.Object2String(rm.get("inviteCode")));
		}else{
			while (gcode==0){
				gcode=insertCoupon(param);
			}
		}
		
		HashMap<String, Object> hm = Maps.newHashMap();
		hm.put("inviteCode", gcode);
		hm.put("downloadURL", "http://www.dibabo.cn/");
		hm.put("content", "我已注册蒂芭卜，下载APP加入我们的家庭吧");
		
		m.put(ApplicationUtils.DATASET, hm);
		m.put(ApplicationUtils.STATUS, "1");
		m.put(ApplicationUtils.MSG, "申请成功");
		
		
		return m;
	}
	
//	int gcode=0;
	//插入优惠表
	public int  insertCoupon(HashMap<String, Object> hm){
		int inviteCode=(int)(Math.random()*90000000+10000000);
		
		try{
			hm.put("inviteCode", inviteCode);
			int effect = ssoMapper.createInviteCode(hm);
			if(effect!=1){
				inviteCode = 0;
			}
		}catch(Exception ex){
			inviteCode = 0;
		}
		return inviteCode;
	}
	
	
	@Override
	public Map<String,Object> acceptInvite(String token,String inviteCode) throws Exception{
		Map<String,Object> retM=new HashMap<String,Object>();
		
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}
		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
		String family_id = jedisCache.hget(token, TokenUtil.FAMILY_ID);
		
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("c_user_id", c_user_id);
		hm.put("inviteCode", inviteCode);
		
		List<Map<String,Object>> familyID=ssoMapper.getFamilyByCode(inviteCode);
		
		if(familyID==null||familyID.size()==0){
			retM.put(ApplicationUtils.STATUS, "0");
			retM.put(ApplicationUtils.MSG, "请输入有效的邀请码");		
			return retM;
		}
		//获取邀请码角色
		String c_role_id = ApplicationUtils.Object2String(((Map<String,Object>)familyID.get(0)).get("c_role_id"));
//		String c_role_id=ssoMapper.getRoleByID(c_user_id);
		//如果邀请码角色为空，则获取注册角色
		if(StringUtils.isBlank(c_role_id)){	
			c_role_id = jedisCache.hget(token, TokenUtil.ROLE_ID);
		}
		if(StringUtils.isNotBlank(c_role_id)){	
			if(c_role_id.equals("2")||c_role_id.equals("1")){
				HashMap<String,Object> hm2=new HashMap<String,Object>();
				hm2.put("c_role_id", c_role_id);
				hm2.put("c_family_id", ApplicationUtils.Object2String(((Map<String,Object>)familyID.get(0)).get("c_family_id")));
				
				int count=ssoMapper.getRoleCount(hm2);
				if(count>0){
					retM.put(ApplicationUtils.STATUS, "0");
					retM.put(ApplicationUtils.MSG, "该家庭已有父母，不能重复添加父母角色");		
					return retM;
				}
			}
		}
		
		HashMap<String,Object> hm3=new HashMap<String,Object>();
		hm3.put("c_user_id", c_user_id);
		hm3.put("c_family_id", ApplicationUtils.Object2String(((Map<String,Object>)familyID.get(0)).get("c_family_id")));
		hm3.put("c_role_id", c_role_id);
		
		int effect=ssoMapper.updateUserFamily(hm3);
		
		if(effect<1){
			retM.put(ApplicationUtils.STATUS, "0");
			retM.put(ApplicationUtils.MSG, "邀请失败");		
			return retM;
		}
		HashMap<String,Object> hm4=new HashMap<String,Object>();
		
		hm4.put("user_id", c_user_id);
		hm4.put("family_id", family_id);
		hm4.put("code", inviteCode);
		
		ssoMapper.updateCode(hm4);
		
		if(StringUtils.isNotBlank(inviteCode)){//如果是邀请，则记录日志
			hm.put("c_role_id", c_role_id);
			ssoMapper.addinviteCodeLog(hm);
		}

		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "邀请成功");		
		return retM;
	}

	@Override
	public Map<String, Object> UnUsedInvites(String token) {
		Map<String, Object> t = TokenUtil.checkToken(token, jedisCache);
		if (t != null) {
			return t;
		}else{
			t = Maps.newHashMap();
		}
		String c_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("c_user_id", c_user_id);
		List<Map<String,Object>> dataset = ssoMapper.getUnUsedInviteCode(hm);
		t.put(ApplicationUtils.DATASET, dataset);
		t.put(ApplicationUtils.STATUS, "1");
		t.put(ApplicationUtils.MSG, "查询成功");		
		return t;
	}
	
	
	
	@Override
	public Map<String, Object> getAppointmentList(String userName,String productTypeCode,String skip, String rows, String pageSize, String pageIndex,
			String EntityAvailableState) throws Exception{
		Map<String,Object> retM=new HashMap<String,Object>();				
		
		HashMap<String,Object> hm=MyTools.pageIndexToSkip(pageSize, pageIndex, skip, rows);
		hm.put("EntityAvailableState", EntityAvailableState);
		hm.put("userName", userName);
		hm.put("productTypeCode", productTypeCode);

		List<Map<String,Object>> list=mainShowMapper.getAppointmentList(hm);
		Integer total = mainShowMapper.getAppointmentListCount(hm);
		
		retM.put(ApplicationUtils.DATASET, list);
		retM.put("total",total);
		retM.put(ApplicationUtils.STATUS, "1");
		retM.put(ApplicationUtils.MSG, "查询成功");		
		return retM;
	}
	
	
	@Override
	public BaseResult getBabyListOrderByName(String kidsParkID) throws Exception{		
		
		List<Map<String,Object>> list=ssoMapper.getBabyListOrderByName(kidsParkID);
		
		return new BaseResult("1","查询成功",list);
	}

	@Override
	public BaseResult teacherCreateJournal(com.spring.appservice.web.requestModel.Journal jouranl) throws Exception{		
		
		String token=jouranl.getToken();
		
		BaseResult t = TokenUtil.checkTokenBR(token, jedisCache);
		if (t != null) {
			return t;
		}
		
		String teacherName = jedisCache.hget(token, TokenUtil.USER_NAME);
		String t_user_id = jedisCache.hget(token, TokenUtil.USER_ID);
		
		
		List<BaseFile> photoList=jouranl.getPhotoList();
		List<BaseFile> vidoeList=jouranl.getVideoList();
		List<JournalUser> UserList=jouranl.getUserList();
		if(UserList==null){
			UserList=new ArrayList<JournalUser>();
		}
		
		String my_space_journal_id=null;
		
		String groupUUID=ApplicationUtils.randomUUID();
		//如果是全部可见
		if(jouranl.getIsForAll()==1){			
			UserList.add(new JournalUser());
		}
		
		for(JournalUser ju:UserList){
			String uuid=ApplicationUtils.randomUUID();

			Map<String,Object> param=new HashMap<String,Object>();
			
			param.put("uuid", uuid);
			param.put("title", jouranl.getTitle());
			param.put("content", jouranl.getContent());
			param.put("cUserID", ju.getcUserID());
			param.put("realName", teacherName);
			param.put("cFamilyID", ju.getcFamilyID());
			param.put("longitude", jouranl.getLongitude());
			param.put("latitude", jouranl.getLatitude());
			param.put("location", jouranl.getLocation());			
			param.put("groupUUID", groupUUID);	
			param.put("t_user_id", t_user_id);
			param.put("mapAppType", jouranl.getMapAppType());
			param.put("osType", jouranl.getOsType());
			
			my_space_journal_id=uuid;
			
/*			if(ju.getcUserID()==null){
				
			}*/
			
			int effect=mainShowMapper.teacherCreateJournal(param);
			if(effect<1){
				throw new Exception();
			}

/*			for(BaseFile bf:photoList){
				HashMap<String,Object> param2=new HashMap<String,Object>();

				param2.put("my_space_journal_id", uuid);
				param2.put("file_id", bf.getFileID());
				param2.put("cFamilyID", ju.getcFamilyID());
				
				int effect2=mySpaceMapper.addJournalPhoto(param2);
				
				if(effect2<1){
					throw new Exception();
				}
			}
			
			for(BaseFile bf:vidoeList){
				HashMap<String,Object> param2=new HashMap<String,Object>();
				
				param2.put("my_space_journal_id", uuid);
				param2.put("file_id", bf.getFileID());
				param2.put("cFamilyID", ju.getcFamilyID());
				
				int effect2=mySpaceMapper.addJournalVideo(param2);
				
				if(effect2<1){
					throw new Exception();
				}
			}*/
		}

		//groupUUID
		List<HashMap<String,Object>> list=new ArrayList<HashMap<String,Object>>();
		HashMap<String,Object> hm=new HashMap<String,Object>();
		hm.put("my_space_journal_id", my_space_journal_id);
		list.add(hm);
		
		return new BaseResult("1","录入成功",list);
	}
	
	@Override
	public BaseResult getMyBabyList(String token,String babyID) throws Exception{		
		
		BaseResult t = TokenUtil.checkTokenBR(token, jedisCache);
		if (t != null) {
			return t;
		}
		
		String parentID = jedisCache.hget(token, TokenUtil.USER_ID);
		
		Map<String,Object> param=new HashMap<String,Object>();
		param.put("babyID", babyID);
		param.put("parentID", parentID);
		
		
		List<com.sso.api.web.model.Baby> list=ssoMapper.getMyBabyList(param);
		
		if(list.size()==0){
			return new BaseResult("1","查询成功",list);
		}
		
		String[] userIDList=new String[list.size()];
		for(int i=0;i<list.size();i++){
			com.sso.api.web.model.Baby baby=list.get(i);
			userIDList[i]=baby.getC_user_id();
		}
		
		Map<String,Object> param2=new HashMap<String,Object>();
		param2.put("userList", userIDList);
		List<com.sso.api.web.model.Baby> mySpaceList=mainShowMapper.getMySpaceCover(param2);	
		
		for(com.sso.api.web.model.Baby baby:list){
			for(com.sso.api.web.model.Baby myspace:mySpaceList){
				if(baby.getC_user_id().equals(myspace.getC_user_id())){
					baby.setCover_url(myspace.getCover_url());
				}
			}
		}
		
		
		return new BaseResult("1","查询成功",list);
	}

	@Override
	public BaseResult kidsPark() throws Exception{		
		
		List<HashMap<String,Object>> list=mainShowMapper.kidsPark();
		
		return new BaseResult("1","查询成功",list);
	}
	
	@Override
	public BaseResult teacherAddPhoto(String my_space_journal_id,String file,String token) throws Exception{		
		
		String[] ids=mainShowMapper.getJournalsByID(my_space_journal_id);
		for(String id:ids){
			Map<String, Object> br=mySpaceService.addJournalPhoto(token, id, null, file);
			if(!br.get(ApplicationUtils.STATUS).equals("1")){
				return new BaseResult((String)br.get(ApplicationUtils.STATUS),(String)br.get(ApplicationUtils.MSG));
			}
		}				
		return new BaseResult("1","插入成功");
	}
	
	@Override
	public BaseResult teacherAddVideo(String my_space_journal_id,String file,String token) throws Exception{		
		
		String[] ids=mainShowMapper.getJournalsByID(my_space_journal_id);
		for(String id:ids){
			Map<String, Object> br=mySpaceService.addJournalVideo(token, null, id, file);
			if(!br.get(ApplicationUtils.STATUS).equals("1")){
				return new BaseResult((String)br.get(ApplicationUtils.STATUS),(String)br.get(ApplicationUtils.MSG));
			}
		}				
		return new BaseResult("1","插入成功");
	}
	


}